import pandas as pd
from sqlalchemy import create_engine

# 数据库连接信息
DB_CONNECTION = "mysql+pymysql://chenkm_view:chenkm#2024@rm-7xv1a7s3xv1608tpi4o.mysql.rds.aliyuncs.com:3306/exhibition_prod"

def get_engine():
    """ 获取连接对象 """
    try:
        engine = create_engine(DB_CONNECTION, pool_size=10, max_overflow=50, pool_timeout=30, pool_recycle=-1)
        return engine
    except Exception as e:
        raise Exception(f"get_engine error: {e}")

def fetch_data(credit_code):
    """ 查询公司表中指定信用代码的记录 """
    try:
        engine = get_engine()
        query = f"SELECT * FROM fh_company WHERE unified_social_credit_code = '{credit_code}'"
        df = pd.read_sql(query, con=engine)
        return df
    except Exception as e:
        raise Exception(f"fetch_data error: {e}")

if __name__ == '__main__':
    credit_code = '91330226MA2J7KC31U'
    df = fetch_data(credit_code)
    print(df)